#-*- coding: utf8 -*-
from tutor.scripts import *
from tutor.plugins.sympy import *

bignum = 50
n_iter = 0
while True:
    # parâmetros iniciais
    with display_block('Entradas'):
        r = One * oneof(1, 2, 3, 4, 5) * oneof(-1, 1)
        s = One * oneof(1, 2, 3, 4, 5) * oneof(-1, 1)
        Fx = (s * x + r * y)
        Fy = (s * y - r * x)

        # parametrizaçao do caminho
        X = a * cos(t)
        Y = a * sin(t)
        Vx, Vy = (f.diff(t) for f in [X, Y])
        FFx = Fx.subs([(x, X), (y, Y)])
        FFy = Fy.subs([(x, X), (y, Y)])
        v = a


    with display_block('Resultados'):
        # Work
        work = 2 * pi * trigsimp(expand(Vx * FFx + Vy * FFy))
        wCCW = -work
        wMod = 2 * pi * trigsimp(expand(FFx ** 2 + FFy ** 2))
        wMCCW = -wMod

    _resps = set([ work, wCCW, wMod, wMCCW ])
    if len(_resps) != 4:
        continue
    else:
        _cont_loop = True
        for _resp in _resps:
            num, den = (_resp / pi / a ** 2).as_numer_denom()
            if num > bignum or den > bignum:
                break
        else:
            _cont_loop = False
        if _cont_loop:
            continue

    with display_block('Distratores'):
        _distr = set()
        _resps = list(_resps)
        while len(_distr) < 4:
            new = choice(_resps) * (One * oneof(1, 2, 3, 4)) / oneof(1, 2, 3, 4)
            if new not in _resps:
                _distr.add(new)
        for d in list(_distr):
            _distr.add(-d)
        distr1, distr2, distr3, distr4, distr5 = list(_distr)[:5]

        n_iter += 1
    break
